﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.APP.Classes;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class MP_JobSiteCommandDtls : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private ICommandBLL cmdBLL = new CommandBLL();
        private IJobsiteCommandDtlsBLL dtlsBLL = new JobsiteCommandDtlsBLL();
        private JobSiteCommandDtlsInfo dtlsInfo;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lblCmdSeq.Text = Request.QueryString["CmdSeq"].ToString();
                LoadDataGrid();
            }
        }
        public void LoadDataGrid()
        {
            Nullable<int> CmdSeq = lblCmdSeq.Text.Length > 0 ? Int32.Parse(lblCmdSeq.Text) : (int?)null;

            DataSet ds = dtlsBLL.LoadJobSiteCommandDtls((int?)null, CmdSeq);
            DataTable dt = null;

            if (ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                RadGrid1.DataSource = dt;
                RadGrid1.DataBind();
            }
        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                dtlsInfo = new JobSiteCommandDtlsInfo();

                string Seq = (e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["JOB_SITE_CMD_DTLS_SEQ"].ToString();

                dtlsInfo.Seq = Seq.Length > 0 ? Int32.Parse(Seq) : (int?)null;
                dtlsInfo.UpdatedBy = ssMng.EmpSeqI;

                dtlsBLL.Delete(dtlsInfo);
            }

            LoadDataGrid();

        }
    }
}
